package com.evaluation_system.mapper;

import com.evaluation_system.pojo.DTO.EvaluatorPageQueryDTO;
import com.evaluation_system.pojo.entity.Evaluator;
import com.evaluation_system.pojo.entity.saveFileInfo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EvaluatorMapper {
    @Select("SELECT * FROM file " +
            "WHERE is_checked = #{isChecked} " +
            "ORDER BY id " +
            "LIMIT #{size} OFFSET #{page};")
    List<saveFileInfo> getFile(@Param("isChecked") Integer isChecked, @Param("size") Integer size, @Param("page") Integer page);

    @Select("SELECT * FROM file WHERE file_name=#{fileName}")
    List<saveFileInfo> getOneFile(String fileName);

    @Select("SELECT file_path FROM file WHERE id = #{id}")
    String getFileUrl(Integer id);

    @Select("SELECT file_name FROM file WHERE id = #{id}")
    String getFileName(Integer id);

    @Select("SELECT secret_key FROM file WHERE id = #{id}")
    String getSecretKey(Integer id);

    @Select("SELECT secret_iv FROM file WHERE id = #{id}")
    String getSecretIV(Integer id);

    @Insert("INSERT INTO score(file_id,evaluator_id,score) VALUES (#{fileId},#{evaluatorId},#{score})")
    void insertScore(@Param("fileId") Integer fileId, @Param("evaluatorId") Integer evaluatorId,@Param("score") Integer score);

    @Select("SELECT score FROM score WHERE file_id = #{fileId}")
    int getScore(Integer fileId);
    @Update("UPDATE score SET score = #{score} WHERE file_id = #{fileId} AND evaluator_id = #{evaluatorId}")
    void updateScore(@Param("score") Integer score,@Param("fileId") Integer fileId, @Param("evaluatorId") Integer evaluatorId);

    Page<Evaluator> pageQuery(EvaluatorPageQueryDTO evaluatorPageQueryDTO);


    @Insert("INSERT INTO evaluator(username,password) VALUES (#{username},#{password})")
    void insert(Evaluator evaluator);

    void update(Evaluator evaluator);

    @Delete("DELETE FROM evaluator WHERE id = #{id}")
    void deleteById(Integer id);
}
